package com.example.zhangpeng.scrollrecyclerview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

import com.example.zhangpeng.scrollrecyclerview.adapter.MyAdapter;
import com.example.zhangpeng.scrollrecyclerview.view.MyRecyclerView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private MyRecyclerView rv;
    private  MyAdapter myAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initListener();
    }

    private void initListener() {
        rv.setOnClickListener(this);
    }

    private void initData() {
         myAdapter=new MyAdapter();
        rv.setAdapter(myAdapter);
      rv.postDelayed(new Runnable() {
          @Override
          public void run() {
              rv.setScrollView(myAdapter.getMyViewHolder().scrollView);
          }
      },3000);
    }

    private void initView(){
        rv = (MyRecyclerView) findViewById(R.id.rv);
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rv.setLayoutManager(linearLayoutManager);
//        rv.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                myAdapter.getMyViewHolder().scrollView.getParent().requestDisallowInterceptTouchEvent(false);
//                return false;
//            }
//        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rv :
                Toast.makeText(v.getContext(),"点击 RecyclerView",Toast.LENGTH_SHORT).show();
                break;
            default:
                break;
        }
    }
}
